package com.zzj.ziputil;

import android.text.TextUtils;
import java.io.File;
import net.lingala.zip4j.core.ZipFile;
import net.lingala.zip4j.exception.ZipException;
import net.lingala.zip4j.model.FileHeader;

/* loaded from: classes2.dex */
public class ZipArchiver extends BaseArchiver {
    @Override // com.zzj.ziputil.BaseArchiver
    public void doArchiver(File[] fileArr, String str) {
    }

    @Override // com.zzj.ziputil.BaseArchiver
    public void doUnArchiver(String str, String str2, String str3, final IArchiverListener iArchiverListener) {
        ZipFile zipFile;
        if (TextUtils.isEmpty(str) || TextUtils.isEmpty(str2) || !new File(str).exists()) {
            return;
        }
        try {
            zipFile = new ZipFile(str);
            zipFile.setFileNameCharset("GBK");
        } catch (ZipException e) {
            e.printStackTrace();
        }
        if (!zipFile.isValidZipFile()) {
            throw new ZipException("文件不合法!");
        }
        File file = new File(str2);
        if (file.isDirectory() && !file.exists()) {
            file.mkdir();
        }
        if (zipFile.isEncrypted()) {
            zipFile.setPassword(str3.toCharArray());
        }
        if (iArchiverListener != null) {
            this.mHandler.post(new Runnable() { // from class: com.zzj.ziputil.ZipArchiver.1
                @Override // java.lang.Runnable
                public void run() {
                    iArchiverListener.onStartArchiver();
                }
            });
        }
        final int size = zipFile.getFileHeaders().size();
        for (final int i = 0; i < zipFile.getFileHeaders().size(); i++) {
            FileHeader fileHeader = (FileHeader) zipFile.getFileHeaders().get(i);
            if (!new File(str2, fileHeader.getFileName()).exists()) {
                zipFile.extractFile(fileHeader, str2);
            }
            if (iArchiverListener != null) {
                this.mHandler.post(new Runnable() { // from class: com.zzj.ziputil.ZipArchiver.2
                    @Override // java.lang.Runnable
                    public void run() {
                        iArchiverListener.onProgressArchiver(i + 1, size);
                    }
                });
            }
        }
        if (iArchiverListener != null) {
            this.mHandler.post(new Runnable() { // from class: com.zzj.ziputil.ZipArchiver.3
                @Override // java.lang.Runnable
                public void run() {
                    iArchiverListener.onEndArchiver();
                }
            });
        }
    }
}
